<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<!--#Include File="comm/cls_makejs.asp" -->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_MakeJs.asp
'= 摘    要：后台-自定义Js定义管理文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2005-10-21
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"46") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "add"
	Call Add
Case "save"
	Call Save
Case "del"
	Call Del
Case "preview"
	Call Preview
Case "make"
	Call MakeJs
Case Else
	Call Main
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing

Sub Main
	Dim i
	Dim ListBlock,Temp,TopicList

	PageContent=Template.LoadTemplate("admin_makejs_list.htm")

	Template.SetVariable "Language_Comm_ListEmpty",str_Comm_ListEmpty,PageContent
	Template.SetVariable "Language_Comm_Bar_Operation",str_Comm_Bar_Operation,PageContent
	Template.SetVariable "Language_Comm_Edit_Operation",str_Comm_Edit_Operation,PageContent
	Template.SetVariable "Language_Comm_Alert_Del_Operation",str_Comm_Alert_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Del_Operation",str_Comm_Del_Operation,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Js_Help",str_Js_Help,PageContent

	Template.SetVariable "Language_Js_List",str_Js_List,PageContent
	Template.SetVariable "Language_Js_Add",str_Js_Add,PageContent
	Template.SetVariable "Language_Js_Title",str_Js_Title,PageContent
	Template.SetVariable "Language_Js_Detail",str_Js_Detail,PageContent
	Template.SetVariable "Language_Js_TransferPath",str_Js_FilePath,PageContent
	Template.SetVariable "Language_Js_UpDate",str_Js_UpDate,PageContent
	Template.SetVariable "Language_Js_Preview",str_Js_Preview,PageContent
	Template.SetVariable "Language_Js_UpDateAll",str_Js_UpDateAll,PageContent
	Template.SetVariable "Language_Js_UpDateSystemJs",str_Js_UpDateSystemJs,PageContent
	Template.SetVariable "SystemFolder",SystemFolder,PageContent


	ListBlock=Template.GetBlock("list",PageContent)

	TopicList=EA_M_DBO.Get_Js_List()
	If IsArray(TopicList) Then
		Template.SetVariable "ListTempty","none",PageContent
	
	    For i=0 To Ubound(TopicList,2)
			Temp=ListBlock
  
			Template.SetVariable "JsID",TopicList(0,i),Temp
			Template.SetVariable "JsTitle",TopicList(1,i),Temp
			Template.SetVariable "JsDetail",TopicList(2,i),Temp
			Template.SetVariable "JsFilepath",TopicList(3,i),Temp
			
			Template.SetBlock "list",Temp,PageContent
		Next
	End If
	Template.CloseBlock "list",PageContent
	

	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Add
	Dim Title,Info,FileName,Setting
	Dim i,TempArray,Level,Code,Temp,ColumnList
	Dim PostId
	
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)

	Temp=EA_M_DBO.Get_Js_Info(PostId)
	If IsArray(Temp) Then 
		Title=Temp(0,0)
		Info=Temp(1,0)
		FileName=Temp(2,0)
		Setting=Split(Temp(3,0),"|")
	End If

	If Not IsArray(Setting) Then ReDim Setting(14):Setting(13)="1"

	Temp=EA_DBO.Get_Column_List()
	If IsArray(Temp) Then
		For i=0 To UBound(Temp,2)
			Level=(Len(Temp(2,i))/4-1)*3
			ColumnList = ColumnList & "<option value="""&Temp(2,i)&""""
			If Setting(0)=Temp(2,i) Then ColumnList = ColumnList & " selected"
			ColumnList = ColumnList & ">"
			ColumnList = ColumnList & "├"
			ColumnList = ColumnList & String(Level,"-")
			ColumnList = ColumnList & Temp(1,i)&"</option>"
		Next
	End If

	PageContent=Template.LoadTemplate("admin_makejs_option.htm")

	Template.SetVariable "Language_Comm_Save_Button",str_Comm_Save_Button,PageContent
	Template.SetVariable "Language_Comm_Reset_Button",str_Comm_Reset_Button,PageContent
	Template.SetVariable "Language_Comm_AllColumn",str_Comm_AllColumn,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Js_Help",str_Js_Help,PageContent

	Template.SetVariable "ColumnList",ColumnList,PageContent

	Template.SetVariable "Language_Js_List",str_Js_List,PageContent
	Template.SetVariable "Language_Js_Add",str_Js_Add,PageContent
	Template.SetVariable "Language_Js_Title",str_Js_Title,PageContent
	Template.SetVariable "Language_Js_Detail",str_Js_Detail,PageContent
	Template.SetVariable "Language_Js_FilePath",str_Js_FilePath,PageContent
	Template.SetVariable "Language_Js_BaseSetting",str_Js_BaseSetting,PageContent
	Template.SetVariable "Language_Js_TransferSetting",str_Js_TransferSetting,PageContent
	Template.SetVariable "Language_Js_TransferColumn",str_Js_TransferColumn,PageContent
	Template.SetVariable "Language_Js_IncludeChildColumn",str_Js_IncludeChildColumn,PageContent
	Template.SetVariable "Language_Js_ListStyle",str_Js_ListStyle,PageContent
	Template.SetVariable "Language_Js_ListStyle_Txt",str_Js_ListStyle_Txt,PageContent
	Template.SetVariable "Language_Js_ListStyle_Detail",str_Js_ListStyle_Detail,PageContent
	Template.SetVariable "Language_Js_ListStyle_Mix",str_Js_ListStyle_Mix,PageContent
	Template.SetVariable "Language_Js_ListStyle_Img",str_Js_ListStyle_Img,PageContent
	Template.SetVariable "Language_Js_TransferTotal",str_Js_TransferTotal,PageContent
	Template.SetVariable "Language_Js_TransferType",str_Js_TransferType,PageContent
	Template.SetVariable "Language_Js_Transfer_AllArticle",str_Js_Transfer_AllArticle,PageContent
	Template.SetVariable "Language_Js_Transfer_CommendArticle",str_Js_Transfer_CommendArticle,PageContent
	Template.SetVariable "Language_Js_Transfer_HotArticle",str_Js_Transfer_HotArticle,PageContent
	Template.SetVariable "Language_Js_Transfer_ImgArticle",str_Js_Transfer_ImgArticle,PageContent
	Template.SetVariable "Language_Js_TitleLen",str_Js_TitleLen,PageContent
	Template.SetVariable "Language_Js_ContentLen",str_Js_ContentLen,PageContent
	Template.SetVariable "Language_Js_ShowFields",str_Js_ShowFields,PageContent
	Template.SetVariable "Language_Js_ShowFields_ColumnName",str_Js_ShowFields_ColumnName,PageContent
	Template.SetVariable "Language_Js_ShowFields_NewTag",str_Js_ShowFields_NewTag,PageContent
	Template.SetVariable "Language_Js_ShowFields_AddTime",str_Js_ShowFields_AddTime,PageContent
	Template.SetVariable "Language_Js_ShowFields_TypeTag",str_Js_ShowFields_TypeTag,PageContent
	Template.SetVariable "Language_Js_ShowFields_ReviewLink",str_Js_ShowFields_ReviewLink,PageContent
	Template.SetVariable "Language_Js_OpenWindowType",str_Js_OpenWindowType,PageContent
	Template.SetVariable "Language_Js_OpenWindowType_Parent",str_Js_OpenWindowType_Parent,PageContent
	Template.SetVariable "Language_Js_OpenWindowType_New",str_Js_OpenWindowType_New,PageContent
	Template.SetVariable "Language_Js_RowTotal",str_Js_RowTotal,PageContent
	Template.SetVariable "Language_Js_ImgSize",str_Js_ImgSize,PageContent
	
	Template.SetVariable "JsID",PostId,PageContent
	Template.SetVariable "JsTitle",Title,PageContent
	Template.SetVariable "JsInfo",Info,PageContent
	Template.SetVariable "JsFileName",FileName,PageContent
	Template.SetVariable "IncludeChildColumn_" & Setting(1)," checked",PageContent
	Template.SetVariable "Style_" & Setting(2)," selected",PageContent
	Template.SetVariable "TransferTotal",Setting(3),PageContent
	Template.SetVariable "Types_" & Setting(4)," selected",PageContent
	Template.SetVariable "TitleLen",Setting(5),PageContent
	Template.SetVariable "ContentLen",Setting(6),PageContent
	Template.SetVariable "ShowColumn_" & Setting(7)," checked",PageContent
	Template.SetVariable "ShowNew_" & Setting(8)," checked",PageContent
	Template.SetVariable "ShowTime_" & Setting(9)," checked",PageContent
	Template.SetVariable "ShowTypes_" & Setting(10)," checked",PageContent
	Template.SetVariable "ShowReview_" & Setting(11)," checked",PageContent
	Template.SetVariable "OpenWindowType_" & Setting(12)," selected",PageContent
	Template.SetVariable "RowTotal",Setting(13),PageContent
	Template.SetVariable "ImgSize",Setting(14),PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Preview
	Dim PostId
	Dim FilePath,Temp
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	Temp=EA_M_DBO.Get_Js_Info(PostId)
	If IsArray(Temp) Then FilePath=Temp(2,0)
%>
<table width="90%" border="0" cellpadding="0" cellspacing="0" align="center" class=TableBorder>
  <tr valign="middle" align="center"> 
    <td><script language="JavaScript" src="../jsfiles/<%=FilePath%>"></script></td>
</table>
<%
End Sub

Sub Save
	Call EA_Pub.Chk_Post
	
	Dim Title,Info,FileName,Setting
	Dim PostId
	
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	Title=EA_Pub.SafeRequest(2,"title",1,"",0)
	Info=EA_Pub.SafeRequest(2,"info",1,"",0)
	FileName=EA_Pub.SafeRequest(2,"filename",1,"",0)
	
	Setting=EA_Pub.SafeRequest(2,"column",1,"",0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"child",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"style",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"top",0,10,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"types",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"titlecut",0,10,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"contentcut",0,50,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"showcolumn",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"shownew",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"showtime",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"showtypes",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"showreview",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"open",0,0,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"row",0,1,0)
	Setting=Setting&"|"&EA_Pub.SafeRequest(2,"imgsize",1,"",0)
	
	If Rs.State=1 Then rs.Close
	If PostId<>0 Then
		Sql="Select * From [NB_JsFile] Where [Id]="&PostId
		rs.Open Sql,Conn,2,2
	Else
		rs.Open "NB_JsFile",Conn,2,2
		rs.AddNew
	End If
		rs("Title")=Title
		rs("FileName")=FileName
		rs("Info")=Info
		rs("Setting")=Setting
		rs.update
	Rs.Close:Set Rs=Nothing
	
	Set Rs=Nothing
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing

	Response.Redirect "admin_makejs.asp"
End Sub

Sub Del
	Call EA_Pub.Chk_Post
	
	Dim PostId
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	EA_M_DBO.Set_Js_Delete PostId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub MakeJs()
	Dim NBArticle_Make,Content
	Dim TempArray,TSQL,TopicList,Temp,JsList,i
	Dim FileName,S
	Dim JsId
	
	JsId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	Set NBArticle_Make=New Cls_MakeJs
	
	If JsId=0 Then 
		SQL="Select FileName,Setting From [NB_JsFile]"
	Else
		SQL="Select FileName,Setting From [NB_JsFile] Where [Id]="&JsId
	End If
	Set Rs=Conn.Execute(SQL)
	If Not rs.eof And Not rs.bof Then 
		JsList=Rs.GetRows()
		
		For i=0 To UBound(JsList,2)
			FileName=JsList(0,i)
			TempArray=Split(JsList(1,i),"|")
				
			TSQL=MakeSQLQuery(TempArray)
			
			If iDataBaseType=0 Then 
				SQL="Select top "&TempArray(3)&" [ID],COLUMNID,COLUMNNAME,TITLE,TCOLOR,AddDate,IsImg,IsTop,Img,left(Summary,"&TempArray(6)&") From [NB_Content] Where IsPass=-1 And IsDel=0"&TSQL
			Else
				SQL="Select top "&TempArray(3)&" [ID],COLUMNID,COLUMNNAME,TITLE,TCOLOR,AddDate,IsImg,IsTop,Img,substring(Summary,1,"&TempArray(6)&") From [NB_Content] Where IsPass=1 And IsDel=0"&TSQL
			End If
			'Response.Write sql
			Set Rs=Conn.Execute(SQL)
			If Not rs.eof And Not rs.bof Then 
				TopicList=Rs.GetRows(TempArray(3))
					
				Select Case TempArray(2)
				Case "0"
				'纯文本模式
					Content=NBArticle_Make.MakeTxtJs(TopicList,CInt(TempArray(7)),CInt(TempArray(9)),CInt(TempArray(8)),CInt(TempArray(10)),CInt(TempArray(11)),CInt(TempArray(5)),CInt(TempArray(6)),CInt(TempArray(12)),CInt(TempArray(13)))
				Case "1"
				'图文(上文+下左图+下右文)
					Temp=Split(TempArray(14),"&")
					
					Content=NBArticle_Make.MakeTxtMoreJs(TopicList,CInt(TempArray(7)),CInt(TempArray(9)),CInt(TempArray(8)),CInt(TempArray(10)),CInt(TempArray(11)),CInt(TempArray(5)),CInt(TempArray(12)),CInt(TempArray(13)),CInt(Temp(0)),CInt(Temp(1)))
				Case "2"
				'图文(上文+下左图+下右标题)
					Temp=Split(TempArray(14),"&")
					
					Content=NBArticle_Make.MakeGlsJs(TopicList,CInt(TempArray(7)),CInt(TempArray(9)),CInt(TempArray(8)),CInt(TempArray(10)),CInt(TempArray(11)),CInt(TempArray(5)),CInt(TempArray(6)),CInt(TempArray(12)),CInt(TempArray(13)),CInt(Temp(0)),CInt(Temp(1)))
				Case "3"
				'图片
					Temp=Split(TempArray(14),"&")
					
					Content=NBArticle_Make.MakeImgJs(TopicList,CInt(TempArray(7)),CInt(TempArray(9)),CInt(TempArray(8)),CInt(TempArray(10)),CInt(TempArray(11)),CInt(TempArray(5)),CInt(TempArray(12)),CInt(TempArray(13)),CInt(Temp(0)),CInt(Temp(1)))
				End Select
			Else
				Content="document.write ('<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""100%"" align=""center""><tr><td height=""22"">·没有任何文章</td></tr></table>');"
			End If

			FileName="../jsfiles/"&FileName
			Call EA_Pub.Save_HtmlFile(FileName,Content)

			ErrMsg = ErrMsg & JsList(0,i) & "</li><li>"
		Next
	End If
	
	Rs.Close
	Set Rs=Nothing
	
	ErrMsg = ErrMsg & str_MakeList_AllComplate
	Call EA_Manager.Error(0)
End Sub

Function MakeSQLQuery(DataArray)
	Dim TempStr
	
	If DataArray(0)<>"0" Then 
		If DataArray(1)="1" Then 
			TempStr=" and columncode like '"&DataArray(0)&"%'"
		Else
			TempStr=" and columncode='"&DataArray(0)&"'"
		End If
	End If
	
	Select Case CInt(DataArray(4))
	Case 1
		TempStr=TempStr&" And istop="&EA_DBO.TrueValue
	Case 3
		TempStr=TempStr&" And isimg="&EA_DBO.TrueValue
	End Select
	
	Select Case DataArray(2)
	Case "0"
		If CInt(DataArray(4))=2 Then 
			TempStr=TempStr&" Order By ViewNum Desc,TrueTime Desc"
		Else
			TempStr=TempStr&" Order By TrueTime Desc"
		End If
	Case "1","2"
		If iDataBaseType=0 Then
			TempStr=TempStr&" Order By IsImg,TrueTime Desc"
		Else
			TempStr=TempStr&" Order By IsImg Desc,TrueTime Desc"
		End If
	Case "3"
		TempStr=TempStr&" Order By TrueTime Desc"
	End Select
	
	MakeSQLQuery=TempStr
End Function
%>